package com.ruoyi.system.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.UserMade;
import com.ruoyi.system.domain.UserMadeGoodsList;
import com.ruoyi.system.dto.UserMadeDTO;
import com.ruoyi.system.mapper.UserMadeMapper;

import lombok.extern.log4j.Log4j2;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: 风离
 * @Date: 2022/07/10/16:52
 * @Description:
 */

@RestController
@RequestMapping("/system/userMade")
@Log4j2
public class UserMadeController extends BaseController {

    @Resource
    private UserMadeMapper userMadeMapper;


    @PostMapping("/changeStatus")
    public AjaxResult changeStatus(@Valid @RequestBody UserMade userMade) {
        int change = userMadeMapper.changeStatus(userMade);
        return AjaxResult.success(change);
    }

    @PostMapping("/listByStatus") //获取用户审核列表
    public AjaxResult listByStatus(@RequestBody@Validated UserMadeDTO userMadeDTO) {
        log.info("获取用户审核列表{}",userMadeDTO);
        PageHelper.startPage(userMadeDTO.getPage(), userMadeDTO.getPageSize());
        List<UserMade> userMadeList = userMadeMapper.selectListByStatus(userMadeDTO.getStatus());
        PageInfo<UserMade> pageInfo = new PageInfo<>(userMadeList);

        return AjaxResult.success(pageInfo);

    }

    @PostMapping("/goodsList")
    public AjaxResult goodsList(@RequestParam("goodsId")Integer goodsId)
    {
        log.info("获取商品列表{}",goodsId);
        List<UserMadeGoodsList> userMadeList = userMadeMapper.selectListByGoodsId(goodsId);
        return AjaxResult.success(userMadeList);
    }
}
